package be.redo.converters;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;

import be.redo.abstractlayer.ServiceMarker;

public class AbstractStringToEntityConverter<Service extends ServiceMarker<Entity>, Entity>
		implements Converter<String, Entity> {
	
	final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	private final Service service;
	   protected AbstractStringToEntityConverter(Service service) {
		  logger.debug("Constructor, service = "+service.getClass().getName());
	      this.service = service;
	   }

	@Override
	public Entity convert(String primaryKey) {
		logger.debug("convert, primaryKey = "+primaryKey);
		Long longPK = Long.parseLong(primaryKey);
		logger.debug("convert, long primaryKey = "+longPK);
		Entity entity = service.read(longPK);
		logger.debug("convert, read Entity = "+entity.toString());
		return entity;
	}

}
